<template>
  <div class="dashboard">
    <!-- 侧边栏菜单 -->
    <aside class="sidebar">
      <h3>后台菜单</h3>
      <ul>
        <li><router-link to="/admin/users">用户管理</router-link></li>
        <li><router-link to="/admin/statistics">数据统计</router-link></li>
        <li><a href="#" @click.prevent="logout">退出登录</a></li>
      </ul>
    </aside>
    <!-- 主内容区 -->
    <main class="main-content">
      <header class="header">欢迎来到后台管理系统</header>
      <section class="content">
        <router-view /> <!-- 子页面内容渲染区域 -->
      </section>
    </main>
  </div>
</template>

<script setup>
import { useRouter } from 'vue-router'
const router = useRouter()
// 退出登录函数
function logout() {
  localStorage.removeItem('token') // 清除 token
  router.push('/admin/login') // 跳转到登录页
}
</script>

<style scoped>
.dashboard {
  display: flex;
  height: 100vh;
  background: #f4f6fa;
}
.sidebar {
  width: 220px;
  background: linear-gradient(180deg, #409eff 0%, #1976d2 100%);
  color: #fff;
  padding: 32px 0;
  box-shadow: 2px 0 8px 0 rgba(64,158,255,0.08);
}
.sidebar h3 {
  text-align: center;
  margin-bottom: 32px;
  font-weight: 600;
  letter-spacing: 2px;
}
.sidebar ul {
  list-style: none;
  padding: 0;
}
.sidebar li {
  margin: 24px 0;
  text-align: center;
}
.sidebar a, .sidebar .router-link-active {
  color: #fff;
  text-decoration: none;
  font-size: 17px;
  padding: 8px 24px;
  border-radius: 6px;
  display: inline-block;
  transition: background 0.2s;
}
.sidebar a:hover, .sidebar .router-link-exact-active {
  background: rgba(255,255,255,0.18);
}
.main-content {
  flex: 1;
  display: flex;
  flex-direction: column;
}
.header {
  background: #fff;
  padding: 20px 32px;
  font-size: 20px;
  font-weight: 500;
  box-shadow: 0 2px 8px 0 rgba(64,158,255,0.04);
}
.content {
  flex: 1;
  padding: 32px;
  background: #f4f6fa;
  min-height: 0;
}
</style> 